package com.my.tool.lucky.web;

import com.my.tool.lucky.LuckyLife;
import com.my.tool.lucky.model.Gift;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
@RequestMapping("/church")
public class GodController {

    private Logger logger = LoggerFactory.getLogger(GodController.class);

    @GetMapping("/doubleBall")
    @ResponseBody
    public Gift doubleBall(int lucyNumber) {
        logger.info("doubleBall receive, lucyNumber={}", lucyNumber);
        try {
            LuckyLife luckyLife = new LuckyLife();
            Gift gift = luckyLife.doubleBall(lucyNumber);
            logger.info("doubleBall finish: {}", gift);
            return gift;
        } catch (Exception e) {
            logger.error("doubleBall error, lucyNumber={} error:", lucyNumber, e);
        }
        return null;
    }

    @GetMapping("/lotto")
    @ResponseBody
    public Gift lotto(int lucyNumber) {
        logger.info("lotto receive, lucyNumber={}", lucyNumber);
        try {
            LuckyLife luckyLife = new LuckyLife();
            Gift gift = luckyLife.lotto(lucyNumber);
            logger.info("lotto finish: {}", gift);
            return gift;
        } catch (Exception e) {
            logger.error("lotto error, lucyNumber={} error:", lucyNumber, e);
        }
        return null;
    }
}
